package com.liu.repository;


import com.liu.domain.student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Created by liu on 17-9-19.
 */
public interface StuRepository extends JpaRepository<student,String> {

    @Query("select s from student s where s.stu_id = ?1")
    public student findById(String stu_id);                   //通过id查



    public List<student> findByCla(String cla);                //通过班级查旬


    public List<student> findByName(String name);            //通过name查询


    @Query(value = "select * from student WHERE name LIKE ?1", nativeQuery = true)
    List<student> findMhName(String name);

    @Query("select s from student s where s.room_id = ?1")
    public List<student> findByRoom(Integer room_id);          //通过宿舍id

    @Query("select s from student s where s.name = ?1 and s.password = ?2")  //登录
    student login(String userName, String password);

    @Query("select s from student s where s.stu_id = ?1 and s.password = ?2")  //登录
    student login1(String userName, String password);


    @Query("select s from student s where s.cla = ?1")
    List<student> getClassStu(String cla);

    @Query("select s from student s where s.room_id = ?1")
    List<student> getRoomStu(int roomId);

    /*@Query(value = "select distinct cla from student", nativeQuery = true)
    List<student> findGetCla();                   */                         //查询所有班级

    @Query("select distinct s.cla from student s")
    List<String> getCla();

}